﻿Imports Microsoft.Reporting.WinForms

Public Class frmInHoaDon
    Public rpName As String
    Private vwhd As vwHoaDonMoi
    Private _hoaDon As tbHoaDon
    Property HoaDon As tbHoaDon
        Get
            Return _hoaDon
        End Get
        Set(value As tbHoaDon)
            _hoaDon = value
            vwhd = (From hd In dt.vwHoaDonMois
                    Where hd.id = value.id
                    Select hd).First
        End Set
    End Property
    Private Sub frmInHoaDon_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Dim report As tbReport = (From r In dt.tbReports Order By r.TenReport).ToList(My.Settings.KieuHoaDon) ' dt.tbReports.Where(Function(s) s.id = My.Settings.KieuHoaDon).FirstOrDefault
        '    If report IsNot Nothing Then
        '        Me.ReportViewer1.LocalReport.ReportPath = report.FileRDLC
        '    Me.ClientSize = New System.Drawing.Size(report.PixelWidth + 10, 500)
        '    End If
        ReportViewer1.LocalReport.ReportPath = rpName
        LoadHoaDon(_hoaDon)
    End Sub

    Public Sub LoadHoaDon(hd As tbHoaDon)
        ReportViewer1.LocalReport.EnableExternalImages = True
        Dim rls = dt.vwHoaDonMois.Where(Function(s) s.id = HoaDon.id)
        Dim ds As New ReportDataSource
        ds.Name = "dsHoaDon"
        ds.Value = rls
        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(ds)
        ReportViewer1.LocalReport.SetParameters(DanhSachThamSo(vwhd, True))
        ReportViewer1.RefreshReport()
    End Sub

End Class